import Vue from 'vue';
// import iView from 'view-design'
import VueI18n from 'vue-i18n'
import EN from './EN'
import CN from './CN'
//引入element-ui 语言包
import elementEN from 'element-ui/lib/locale/lang/en'
import elementZH from 'element-ui/lib/locale/lang/zh-CN'
// 引入iview的中英文翻译
// import iviewZH from 'view-design/dist/locale/CN'
// import iviewEN from 'view-design/dist/locale/EN'

Vue.use(VueI18n)
Vue.locale = () => {}

var locale = localStorage.getItem('lang') ? localStorage.getItem('lang') : 'CN';
export const i18n = new VueI18n({
  locale: locale,
  fallbackLocale: 'CN',
  messages: {
    'EN': {
      ...EN,
      ...elementEN
    },
    'CN': {
      ...CN,
      ...elementZH
    },
  }, // 本地与iview国际结合
  silentTranslationWarn: process.NODE_ENV === 'production' // true 去除console中黄色报错
})

Vue.use({
  i18n: (key, value) => i18n.t(key, value)
})

// 切换中英文调用该方法
export function setI18nLanguage(lang) {
  i18n.locale = lang
  document.querySelector('html').setAttribute('lang', lang)
  return lang
}
